<template>
	<view>
		<view class="ffffff flexcenter">
			<u-tabs :list="list1" lineColor="#2361FF" @click="changetab" :activeStyle="{
				    color: '#333333',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'
				}" :inactiveStyle="{
				            color: '#999999',
							fontWeight: '500',
				            transform: 'scale(1)'
				        }" itemStyle="padding-left: 20px; padding-right: 20px; height: 44px;"></u-tabs>
		</view>
		<view class="mainpadding2">
			<view class="margin_top" v-for="item in list.data" :key="item.id" :class="item.status==10?'yhbjt':'ygqbjt'">
				<view class="flexbetween">
					<view class="fonweight xiaohong" style="font-size: 45rpx;">￥{{Number(item.price).toFixed(0)}}
					</view>
					<view class="flexbetween" style="width: 74%;">
						<view class="">
							<view class="flexleft">
								<view class="ershiba fonweight">{{item.name}}</view>
							</view>
							<view class="xiaohui strongtext margin_top2">{{item.end_time_text}}到期</view>
						</view>
						<view class="">
							<view class="honbtn flexcenter" v-if="item.status==10">使用</view>
							<image class="ysyb" src="../static/image/system/ysy.png" v-if="item.status==20" mode=""></image>
							<image class="ysyb" src="../static/image/system/ygq.png" v-if="item.status==30" mode=""></image>
						</view>
					</view>
				</view>
				<view class="smalltext xiaohui margin_top4">请在{{item.end_time_text}}前使用</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list1: [{
						name: '全部',
						value: 0,
					},
					{
						name: '未使用',
						value: 10,
					}, {
						name: '已使用',
						value: 20,
					},
					{
						name: '已失效',
						value: 30,
					}
				],
				tabsid: 0,
				page: 1,
				limit: 12,
				list:{
					data:[]
				},
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/user/userCoupon', 'GET', {
					page: page || 1,
					limit: _this.limit,
					status:this.tabsid
				}).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			changetab(e) {
				this.tabsid = e.value
				this.init()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.xhbtn {
		font-size: 18rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FF0000;
		width: 72rpx;
		height: 32rpx;
		border-radius: 5rpx 5rpx 5rpx 5rpx;
		border: 1rpx solid #FF0000;
	}
	.ysyb {
		width: 80rpx;
		height: 80rpx;
	}

	.honbtn {
		width: 120rpx;
		height: 48rpx;
		background: #FF0000;
		border-radius: 25rpx 25rpx 25rpx 25rpx;
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.yhbjt {
		padding: 36rpx 32rpx 10rpx 35rpx;
		background-size: 100% 100%;
		background-image: url("@/static/image/system/yhq.png");
	}
	.ygqbjt {
		padding: 36rpx 32rpx 10rpx 35rpx;
		background-size: 100% 100%;
		background-image: url('@/static/image/system/ysybg.png');
	}
</style>